<template>
    <div>
        <ul class="menu_top_list ">
            <li @click="add()">
                <span class="iconfont icon-fanhui"></span>
            </li>
            <li>
                搜索结果
            </li>
            <li>

            </li>

        </ul>
        <div class="mag20 md-result">
            <van-list v-model="loading" :finished="finished" finished-text="没有更多游戏了" @load="onLoad">

                <div class="md-list">
                    <div id="list_box">

                        <ul>
                            <van-cell class="list-div" v-for=" (k, index) in  this.con " :key="'i-fo-' + index">
                                <li>
                                    <router-link :to="'./GameDetails?id=' + k.id">


                                        <img :src="k.pic"><em>{{ k.title }}</em>

                                        <p>{{ k.html5introduce }}</p><span>{{ k.category }} | 人气:{{
                                                k.wapclicks
                                        }}</span><i class="icon-"></i>
                                    </router-link>
                                    <router-link :to="'/start?id=' + k.id" tag="a" class="btn">开始玩
                                    </router-link>

                                </li>
                            </van-cell>
                        </ul>


                    </div>
                </div>

            </van-list>


        </div>

    </div>
</template>
<script>
import { allGame } from '@/api/home';

export default {
    data() {
        return {
            text: "",
            show: false,
            newVip: null,
            historyList: [],
            list: [],
            inputValue: "",
            cartoonList: [],
            isShow: false,
            focusState: false,
            loading: false,
            finished: false,
            count: 1,
            scrollTop: "",//距离顶部的距离
            scrollHeight: "",//总共的高
            offsetHeight: "",//当前页面的高.
            active: 0,
            con: null
        };

    },

    methods: {
        add() {
            this.$router.go(-1)

        },
        onLoad() {
            // 异步更新数据
            // setTimeout 仅做示例，真实场景中一般为 ajax 请求
            //当前高度
            this.scrollTop =
                window.pageYOffset ||
                document.documentElement.scrollTop ||
                document.body.scrollTop;
            //总高度
            this.scrollHeight = document.body.scrollHeight;
            //当前屏幕高度
            this.offsetHeight = document.body.offsetHeight;

            if (this.scrollTop + this.offsetHeight + 500 >= this.scrollHeight) {
                setTimeout(() => {
                    for (let i = 0; i < 5; i++) {
                        this.con = this.list.slice(0, this.count++)








                        // console.log("con=", this.con);
                    }


                    // 加载状态结束
                    this.loading = false;

                    // 数据全部加载完成
                    if (this.con.length >= this.list.length) {
                        this.finished = true;
                    }
                }, 1000);
            }
        }


    },
    mounted() {

        allGame().then((data) => {
            let arr = data.data;
            const map = new Map()

            this.cartoonList = arr.filter(key => !map.has(key.id) && map.set(key.id, 1)) // 这里对name属性进行去重

            this.cartoonList.map(item => {

                if (item.title.indexOf(this.$route.query.key) !== -1 || item.category.indexOf(this.$route.query.key) !== -1) {
                    this.list.push(JSON.parse(JSON.stringify(item)));
                    console.log("list", this.list);
                }
            })

        });

        console.log("key", this.$route.query.key);
    },

}
</script>
<style lang="scss" scoped>
.md-list li span {
    height: 18px;
    line-height: 18px;
    color: #959595;
    font-size: 11px;
}

.md-list li p {
    height: 16px;
    line-height: 16px;
    padding-right: 75px;
    color: #959595;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.md-list li .btn {
    position: absolute;
    top: 13.5px;
    right: 0;
    width: 64px;
    height: 12px;
    line-height: 12px;
    padding: 8px 0;
    text-align: center;
    border-radius: 5px;
    border: 1px solid #00cc7d;
    color: #00cc7d;
}

.md-list li em,
.md-list li span,
.md-list li p {
    display: block;
    margin-left: 65px;
}

.md-list li em {
    display: inline-block;
    margin-left: 10px;
    height: 18px;
    line-height: 18px;
    font-size: 14px;
    padding-right: 75px;
    margin-bottom: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}



em,
i {
    font-style: normal;
    vertical-align: top;
}

.md-list li {
    position: relative;
    margin: 3px 0 15px;
    background: #fff;
    height: 55px;

    margin-bottom: 17px;
}

.list-head {
    padding: 5px 10px;
    margin-bottom: 0;
    background-color: #f5f5f5 !important;
    margin-bottom: 15px;
    height: 19px;
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 15px;

}

.md-list li a:first-child {
    height: 55px;
}

.md-list li a {
    display: block;
    position: relative;
}

.md-list li img {
    float: left;
    width: 55px;
    height: 55px;
    border-radius: 12px;
}

.mag20 {

    margin: 48px 10px;
}

.menu_top_list {
    max-width: 500px;
    margin: 0 auto;
    position: fixed;
    height: 48px;
    width: 100%;
    background-color: white;
    color: #333;
    font-size: 16px;
    font-weight: bold;

    z-index: 90;
    top: 0;
}


.menu_top_list li+li {
    width: 64%;
    -webkit-box-pack: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.menu_top_list li {
    float: left;
    display: -webkit-box;
    -webkit-box-align: center;
    height: 48px;
}

.menu_top_list li:first-child {
    cursor: pointer;
    width: 18%;
    color: #BFBFBF;
    font-size: 20px
}

.menu_top_list li:last-child {
    width: 18%;
}

.menu_top_list li:first-child::before {
    background: url("https://rs.sfacg.com/web/m/images/menu_top_icon.png") no-repeat -49.216px 9.96px;
    background-size: 105.462px;
    content: "";
    height: 46.8px;
    width: 24.608px;
    display: block;
}
</style>